using Game.Networking.Client;
using TMPro;
using UnityEngine;

namespace Game.UI {
	public class ClientUIHolder : UIHolder {
		public TMP_Text CameraPositionText;

		protected override void Awake() {
			base.Awake();
			_dataProvider = new ClientComputingUnitUserDataProvider();
		}

		private void Update() {
			var cam = SpectatorCamera.Instance;
			if ( cam ) {

				var id = ClientScriptingController.Instance?.GetAttachedEntityId() ?? 0;
				if ( id > 0) {
					var e = ClientEntityController.Instance.GetEntityById(id);
					if ( e != null ) {
						cam.ConfineTarget = e.transform;
					}
				}
				var pos = cam.transform.position;
				CameraPositionText.text = $"View position: {Mathf.RoundToInt(pos.x)} {Mathf.RoundToInt(pos.y)} {Mathf.RoundToInt(pos.z)}";
			}
		}
	}
}
